package com.group9.service.impl;

import com.group9.dto.DetailActivityFruit;
import com.group9.dto.DetailFruitCategory;
import com.group9.dto.FruitDetail;
import com.group9.mapper.DetailActivityFruitMapper;
import com.group9.mapper.DetailFruitCategoryMapper;
import com.group9.mapper.FruitInfoMapper;
import com.group9.mapper.FruitPicMapper;
import com.group9.pojo.FruitInfo;
import com.group9.pojo.FruitPic;
import com.group9.pojo.FruitPicExample;
import com.group9.service.FruitDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Lcouncillor on 2020/5/23.
 */
@Service
public class FruitDetailServiceImpl implements FruitDetailService {

    @Autowired
    DetailActivityFruitMapper detailActivityFruitMapper;
    @Autowired
    DetailFruitCategoryMapper detailFruitCategoryMapper;
    @Autowired
    FruitInfoMapper fruitInfoMapper;
    @Autowired
    FruitPicMapper fruitPicMapper;

    @Override
    public List<DetailActivityFruit> selectActivityFruitByFruitId(Integer fruitId) {
        return detailActivityFruitMapper.selectByFruitId(fruitId);
    }

    @Override
    public List<DetailFruitCategory> selectFruitCategoryByFruitId(Integer fruitId) {
        return detailFruitCategoryMapper.selectByFruitId(fruitId);
    }

    @Override
    public List<FruitPic> selectFruitPicByFruitId(Integer fruitId) {
        FruitPicExample fruitPicExample = new FruitPicExample();
        FruitPicExample.Criteria criteria = fruitPicExample.createCriteria();
        criteria.andFruitIdEqualTo(fruitId);
        return fruitPicMapper.selectByExample(fruitPicExample);
    }

    @Override
    public FruitDetail selectFruitDetailByFruitId(Integer fruitId) {
        FruitInfo fruitInfo = fruitInfoMapper.selectByPrimaryKey(fruitId);
        FruitDetail fruitDetail = new FruitDetail();
        if ( fruitInfo != null ){
            fruitDetail.setFruitId(fruitId);
            fruitDetail.setFruitName(fruitInfo.getFruitName());
            fruitDetail.setFruitPrice(fruitInfo.getFruitPrice());
            fruitDetail.setFruitActivityCost(fruitInfo.getFruitActivityCost());
            fruitDetail.setSalesVolume(fruitInfo.getSalesVolume());
            fruitDetail.setFruitDescript(fruitInfo.getFruitDescript());

            fruitDetail.setFruitPics(selectFruitPicByFruitId(fruitId));
            fruitDetail.setDetailActivityFruits(selectActivityFruitByFruitId(fruitId));
            fruitDetail.setDetailFruitCategories(selectFruitCategoryByFruitId(fruitId));

            return fruitDetail;
        }
        return null;
    }
}
